package com.qfhd.soft.cjzcore.TaskCenter.ADModel;

import androidx.annotation.NonNull;

import com.qfhd.soft.cjzcore.Core.CJJsonUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

public class ADResourceModel {
    public int ggResource;
    public int weight;
    public String ggID;

    public static ArrayList<ADResourceModel> getArrayADResourceModel(JSONArray array){
        ArrayList<ADResourceModel> tmp = new ArrayList<ADResourceModel>();
        for (int i=0; i<array.length(); i++){
            try {
                JSONObject obj = array.getJSONObject(i);
                ADResourceModel model = getADResourceModel(obj);
                tmp.add(model);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return tmp;
    }

    public static ADResourceModel getADResourceModel(JSONObject obj){
        ADResourceModel model = new ADResourceModel();
        model.ggResource = CJJsonUtils.getValueFromKey_int(obj,"ggResource");
        model.weight = CJJsonUtils.getValueFromKey_int(obj,"weight");
        model.ggID = CJJsonUtils.getValueFromKey_string(obj,"ggID");
        return model;
    }

    @NonNull
    @Override
    public String toString() {
        return "ggResource:" + ggResource + " weight:" + weight + " ggID:" + ggID;
    }
}
